package com.wmlive.hhvideo.heihei.beans.message;

import com.google.gson.Gson;
import com.tencent.bugly.b;
import com.wmlive.hhvideo.common.base.BaseModel;
import com.wmlive.hhvideo.heihei.beans.bell.BellContent;
import com.wmlive.hhvideo.heihei.beans.main.Author;
import com.wmlive.hhvideo.heihei.db.datatable.IMMessageDefaultTable;
import com.wmlive.hhvideo.heihei.db.datatable.IMMessageUserTable;
import com.wmlive.hhvideo.heihei.recordvideo.utils.Utils;
import com.wmlive.hhvideo.utils.KLog;
import com.wmlive.hhvideo.utils.TimeUtil;

import org.json.JSONObject;

/**
 * IM 消息体
 * Created by kangzhen on 2017/7/6.
 */

public class IMMessageBean extends BaseModel {
    private String msg_type;//消息类型
    private Author from_user;//来源用户信息
    private Author to_user;
    private BellContent content;
    private String msg_id;
    private String create_time;
    private String tips;
    private int isRead;//0 未读，1：已读

    public IMMessageBean() {
    }

    public IMMessageBean(String msg_type, Author from_user, Author to_user, BellContent content, String msg_id, String create_time, String tips, int isRead) {
        this.msg_type = msg_type;
        this.from_user = from_user;
        this.to_user = to_user;
        this.content = content;
        this.msg_id = msg_id;
        this.create_time = create_time;
        this.tips = tips;
        this.isRead = isRead;
    }

    public String getMsg_type() {
        return msg_type;
    }

    public void setMsg_type(String msg_type) {
        this.msg_type = msg_type;
    }

    public Author getFrom_user() {
        return from_user;
    }

    public void setFrom_user(Author from_user) {
        this.from_user = from_user;
    }

    public Author getTo_user() {
        return to_user;
    }

    public void setTo_user(Author to_user) {
        this.to_user = to_user;
    }

    public BellContent getContent() {
        return content;
    }

    public void setContent(BellContent content) {
        this.content = content;
    }

    public String getMsg_id() {
        return msg_id;
    }

    public void setMsg_id(String msg_id) {
        this.msg_id = msg_id;
    }

    public String getCreate_time() {
        return create_time;
    }

    public void setCreate_time(String create_time) {
        this.create_time = create_time;
    }

    public String getTips() {
        return tips;
    }

    public void setTips(String tips) {
        this.tips = tips;
    }


    public int getIsRead() {
        return isRead;
    }

    public void setIsRead(int isRead) {
        this.isRead = isRead;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("IMMessageBean{" +
                "msg_type='" + msg_type + '\'');
        if(from_user!=null){
            sb.append( ", from_user=" ).append(from_user.toString());
        }else{
            sb.append( ", from_user=\"\"" );
        }
        if(to_user!=null){
            sb.append("，to_user=").append(to_user.toString());
        }else {
            sb.append("，to_user=\"\"");
        }
        if(content!=null){
            sb.append( ", content=").append(new Gson().toJson(content));
        }else {
            sb.append( ", content=");
        }
        sb.append(", msg_id='" + msg_id + '\'' +
                ", create_time='" + create_time + '\'' +
                ", tips='" + tips + '\'' +
                '}');
        return sb.toString();
    }

    /**
     * 转换为用户的信息表
     * @return
     */
    public IMMessageUserTable  IMMessageBeanToIMMessageUserEntry(){
        IMMessageUserTable imMessageUserEntry = new IMMessageUserTable();
        imMessageUserEntry.setMsg_type(this.getMsg_type());
        imMessageUserEntry.setCreate_time(this.getCreate_time());
        imMessageUserEntry.setCreate_time_db(Utils.getCurrentTimeMillis());
        imMessageUserEntry.setIsRead(0);
        imMessageUserEntry.setMsg_id(this.getMsg_id());
        imMessageUserEntry.setTips(this.getTips());
        if(this.getFrom_user()!=null){
            imMessageUserEntry.setFrom_user(new Gson().toJson(this.getFrom_user()));
        }else{
            imMessageUserEntry.setFrom_user("");
        }
        if(this.getTo_user()!=null){
            imMessageUserEntry.setTo_user(new Gson().toJson(this.to_user));
        }else{
            imMessageUserEntry.setFrom_user("");
        }

        if(this.getContent()!=null){
            imMessageUserEntry.setContent(new Gson().toJson(this.getContent()));
        }else{
            imMessageUserEntry.setContent("");
        }
        return imMessageUserEntry;
    }

    /**
     * 转换为用户的信息表
     * @return
     */
    public IMMessageDefaultTable  IMMessageBeanToIMMessageDefaultEntry(){
        IMMessageDefaultTable imMessageDefaultEntry = new IMMessageDefaultTable();
        imMessageDefaultEntry.setMsg_type(this.getMsg_type());
        imMessageDefaultEntry.setCreate_time(this.getCreate_time());
        imMessageDefaultEntry.setCreate_time_db(Utils.getCurrentTimeMillis());
        imMessageDefaultEntry.setIsRead(0);
        imMessageDefaultEntry.setMsg_id(this.getMsg_id());
        imMessageDefaultEntry.setTips(this.getTips());
        if(this.getFrom_user()!=null){
            imMessageDefaultEntry.setFrom_user(new Gson().toJson(this.getFrom_user()));
        }else{
            imMessageDefaultEntry.setFrom_user("");
        }
        if(this.getTo_user()!=null){
            imMessageDefaultEntry.setTo_user(new Gson().toJson(this.to_user));
        }else{
//            imMessageDefaultEntry.setFrom_user("");
            imMessageDefaultEntry.setTo_user("");
        }

        if(this.getContent()!=null){
            imMessageDefaultEntry.setContent(new Gson().toJson(this.getContent()));
        }else{
            imMessageDefaultEntry.setContent("");
        }
        return imMessageDefaultEntry;
    }
}
